package com.ruoyi.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ruoyi.domain.T03;
import com.ruoyi.domain.T18;
import com.ruoyi.entity.VO.T09VO;
import com.ruoyi.mapper.T03Mapper;
import com.ruoyi.mapper.YYDT09Mapper;
import com.ruoyi.service.IT18Service;
import com.ruoyi.service.YYDIT09Service;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.domain.T09;


/**
 * 知识库Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-27
 */
@Service
public class YYDT09ServiceImpl implements YYDIT09Service
{
    @Autowired
    private YYDT09Mapper t09Mapper;
    @Autowired
    private T03Mapper t03Mapper;
    @Autowired
    private IT18Service it18Service;
    /**
     * 修改知识库
     *
     * @param t09 知识库
     * @return 结果
     */
    @Override
    public int updateT09(T09 t09)
    {
        return t09Mapper.updateT09(t09);
    }

    @Override
    public List<T09VO> selectT12V0List(T09 t09) {
        List<T09> t09S = t09Mapper.selectT09List(t09);
        //得到F0301s
        List<Long> f0301s=t09S.stream().map(T09::getF0301).collect(Collectors.toList());
        //得到F1801s
        List<Long> f1801s=t09S.stream().map(T09::getF1801).collect(Collectors.toList());
        //根据F0301 获取 T03list 转换为 Map
        Map<Long, String> t03Collect = t03Mapper.selectByListF0301s(f0301s)
                .stream().collect(Collectors.toMap(T03::getF0301, T03::getF0302));
        //根据F1801 获取 T18list 转换为Map
        Map<Long, String> t18Collect = it18Service.selectT18ListByF1801s(f1801s)
                .stream().collect(Collectors.toMap(T18::getF1801, T18::getF1804));
        List<T09VO> t09VOList=new ArrayList<>();
        for (T09 t091 : t09S){
            T09VO t09VO=new T09VO();
            BeanUtils.copyProperties(t091,t09VO);
            //设置F0302
            t09VO.setF0302(t03Collect.get(t091.getF0301()));
            //设置F1804
            t09VO.setF1804(t18Collect.get(t091.getF1801()));
            t09VOList.add(t09VO);
        }
        return t09VOList;
    }
}
